﻿/*  
cd /projects/hsieh_project/proj_201809/code_1_data/
qsas data_1_ind_sum.sas 5 &
*/

libname hr "/projects/hsieh_project/proj_201809/data/";

%Let dir_out = /projects/hsieh_project/proj_201809/data/;


/*---------------------------------------------------------*/
/* Load Raw Data */
/*---------------------------------------------------------*/

%include "/projects/hsieh_project/proj_201809/code_1_data/m_read.sas" /source2;
%m_read(param_dev=1,param_lyear=0,param_czone=1,param_msa1983=1,param_msacz=1,param_drop=1);

/*---------------------------------------------------------*/
/* Aggreate to desired level */
/*---------------------------------------------------------*/

%include "/projects/hsieh_project/proj_201809/code_1_data/data_0_ind_sum_core.sas" /source2;

%ind_sum(dt_in=lbd, dt_out=lbd_ind, l_perc=1 10 20 30 40 50 60 70 80 90);
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_fips, c_city=fips, l_perc=1 10 20 30 40 50 60 70 80 90);
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_msa, c_city=msa, l_perc=1 10 20 30 40 50 60 70 80 90);
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_czone, c_city=czone, l_perc=1 10 20 30 40 50 60 70 80 90);
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_msa1983, c_city=msa1983, l_perc=1 10 20 30 40 50 60 70 80 90);
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_msa1983cz, c_city=msa1983cz, l_perc=1 10 20 30 40 50 60 70 80 90);

data lbd;
   set lbd;
   if zipcode = "" then delete;
   zipcode = substr(zipcode,1,5);
run;
%ind_sum_city(dt_in=lbd, dt_out=lbd_ind_zip, c_city=zip, l_perc=1 10 20 30 40 50 60 70 80 90);

/* Drop the automatically generated unwanted variables (already dropped) */

/*
--------------------------------------------------------------------------------
Export
*/

data lbd_ind;
  merge lbd_ind lbd_ind_zip lbd_ind_fips lbd_ind_msa lbd_ind_czone lbd_ind_msa1983 lbd_ind_msa1983cz;
  by year sector ch_ind;
run;

proc export data=lbd_ind outfile="&dir_out./ind_sum_all.dta" replace;
run;


/* End of SAS file */
